﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Riel_Gestion.entities;
using System.Data.OleDb;
using System.Data;
using System.Configuration;
using System.Windows.Forms;

namespace Riel_Gestion.dao
{
    class ProveedorDAO
    {
        private static String SQL_SELECT_BY_ID = "SELECT CODPROVEEDOR, NOMBRE, RESPONSABLE, TELEFONO, DIRECCION, EMAIL, OTROS FROM PROVEEDORES WHERE CODPROVEEDOR = ?";

        private static OleDbConnection conn;
        private static OleDbCommand cmd;
        private static OleDbDataAdapter adapter;
        private static OleDbDataReader reader;

        public static DTOProveedor getData(String idProveedor)
        {
            DTOProveedor proveedor = null;
            try
            {
                proveedor = new DTOProveedor();
                conn = conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["rielConnectionString"].ConnectionString);
                cmd = new OleDbCommand(SQL_SELECT_BY_ID, conn);
                conn.Open();

                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("CODPROVEEDOR", idProveedor);

                reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    proveedor.CodProveedor = long.Parse(reader["CODPROVEEDOR"].ToString());
                    proveedor.Nombre = reader["NOMBRE"].ToString();
                    proveedor.Responsable = reader["RESPONSABLE"].ToString();
                    proveedor.Telefono = reader["TELEFONO"].ToString();
                    proveedor.Direccion = reader["DIRECCION"].ToString();
                    proveedor.Email = reader["EMAIL"].ToString();
                    proveedor.Otros = reader["OTROS"].ToString();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                if (conn != null)
                    conn.Close();
            }
            return proveedor;
        }

        internal static int exist(string p)
        {
            throw new NotImplementedException();
        }

        internal static DTOSaldo getSaldosTotalesById(string p)
        {
            throw new NotImplementedException();
        }
    }
}
